from dao.es_dao.p_health_log_dao import find_health_log_dao, find_health_exception_imei


async def find_health_log(data):
    logs = await find_health_log_dao(data)
    return logs


# 定义一个异步函数，用于获取异常数量
async def get_exception_count(data: dict, depart: list):
    # 调用find_health_exception_imei函数，传入data和depart参数，获取buckets
    buckets = await find_health_exception_imei(data, depart)
    # 定义一个空列表，用于存储response_data
    response_data = []
    # 遍历buckets
    for b in buckets:
        # 定义一个空列表，用于存储data2
        data2 = []
        # 遍历b['field2']['buckets']
        for b1 in b['field2']['buckets']:
            # 将b1添加到data2中
            data2.append(b1)
        # 定义一个字典，用于存储key、doc_count和data2
        data1 = {
            'key': b['key'],
            'count': b['doc_count'],
            'data2': data2
        }
        # 将data1添加到response_data中
        response_data.append(data1)
    # 返回response_data
    return response_data
